home *** CD-ROM | disk | FTP | other *** search
- unit Scanners;
-
- interface
-
- uses
- { Scanners need to know about TTable objects. }
- DBTables,
- { Scanners need to know about table states. }
- DB;
-
- type
-
- {--------------------------------------------------------------
- TTableScanner is the base abstact class for all table
- scanner objects
- }
- TTableScanner = class( TObject )
- private
- { SourceTable is the table that will be scanned through. }
- SourceTable: TTable;
- public
- { Execute performs the actual scanning of the SourceTable. }
- procedure Execute; virtual; abstract;
- constructor Create( ATable: TTable );
- end;
-
- {--------------------------------------------------------------
- TScannerAction is a procedural type. The TScannerAction
- procedure will need to be defined by clients of the
- TTableActionScanner object.
- }
-
- TScannerAction = procedure( SourceTable: TTable );
-
- {--------------------------------------------------------------
- TScannerCondition is another procedural type that will need
- to be defined by clients of the TTableActionScanner object.
- Its purpose is that of decideing whether the TScannerAction
- is applicable or not to the current record in the
- SourceTable. It is used only in conditional scanners.
- }
-
- TScannerCondition = function( SourceTable: TTable ): Boolean ;
-
- {--------------------------------------------------------------
- TScannerTrasferAction is yet another procedural type that
- representing a procedure capable of transferring information
- from a SourceTablle to a TargetTable.
- }
-
- TScannerTransferAction = procedure(
- SourceTable, TargetTable: TTable
- );
-
- {--------------------------------------------------------------
- The TTableActionScanner is capable of applying an Action
- to all records of its SourceTable.
- }
- TTableActionScanner = class( TTableScanner )
- public
- {------------------------------------------------------------
- The TTableActionScanner contains an Action field, the type
- of which is the procedural type TScannerAction. This field
- will need to be initialized with the actual action
- action procedure. In other words, this fields "points" to
- the action (procedure) to be performed on each record
- of the SoruceTable.
- }
- Action: TScannerAction;
- procedure Execute; override;
- constructor Create(
- ATable: TTable;
- AnAction: TScannerAction
- );
- end;
-
- {--------------------------------------------------------------
- The TTableConditionalActionScanner is capable of applying an
- Action of all records of its SourceTalbe that pass the
- Condition test.
- }
- TTableConditionalActionScanner = class( TTableActionScanner )
- public
- {------------------------------------------------------------
- The TTableConditionalActionScanner is similar to the
- TTableActionScanner, except that the action is
- conditioned. Again, the actual condition is expressed
- by a procedural type, the Condition field, which will have
- to be defined by clients of this class.
- }
- Condition: TScannerCondition;
- procedure Execute; override;
- constructor Create(
- ATable: TTable;
- AnAction: TScannerAction;
- ACondition: TScannerCondition
- );
- end;
-
- {--------------------------------------------------------------
- The TTableTransferScanner is capable of transferring all
- records from its SourceTable to its TargetTable.
- }
- TTableTransferScanner = class( TTableScanner )
- private
- TargetTable : TTable;
- public
- TransferAction: TScannerTransferAction;
- procedure Execute; override;
- constructor Create(
- ASourceTable: TTable;
- ATargetTable: TTable;
- ATransferAction: TScannerTransferAction
- );
- end;
-
- {--------------------------------------------------------------
- The TTableConditionalTransferScanner is capable of
- transferring, from its SourceTable to its TargetTable, all
- of the records that pass the TransferCondition.
- }
- TTableConditionalTransferScanner = class(TTableTransferScanner)
- public
- TransferCondition: TScannerCondition;
- procedure Execute; override;
- constructor Create(
- ASourceTable: TTable;
- ATargetTable: TTable;
- ATransferAction: TScannerTransferAction;
- ATransferCondition: TScannerCondition
- );
- end;
-
- { UNIT IMPLEMENTATION SECTION
- ----------------------------------------------------------------}
-
- implementation
-
- { TTableScanner Constructor
- ----------------------------------------------------------------}
- constructor TTableScanner.Create( ATable: TTable );
- begin
- inherited Create;
- SourceTable := ATable;
- end;
-
- { TTableActionScanner Constructor
- ----------------------------------------------------------------}
- constructor TTableActionScanner.Create(
- ATable: TTable;
- AnAction: TScannerAction
- );
- begin
- inherited Create( ATable );
- Action := AnAction;
- end;
-
- { TTableConditionalActionScanner Constructor
- ----------------------------------------------------------------}
- constructor TTableConditionalActionScanner.Create(
- ATable: TTable;
- AnAction: TScannerAction;
- ACondition: TScannerCondition
- );
- begin
- inherited Create( ATable, AnAction );
- Condition := ACondition;
- end;
-
- { TTableTransferScanner Constructor
- ----------------------------------------------------------------}
- constructor TTableTransferScanner.Create(
- ASourceTable: TTable;
- ATargetTable: TTable;
- ATransferAction: TScannerTransferAction
- );
- begin
- inherited create( ASourceTable );
- TargetTable := ATargetTable;
- TransferAction := ATransferAction;
- end;
-
- { TTableConditionalTransferScanner Constructor
- ----------------------------------------------------------------}
- constructor TTableConditionalTransferScanner.Create(
- ASourceTable: TTable;
- ATargetTable: TTable;
- ATransferAction: TScannerTransferAction;
- ATransferCondition: TScannerCondition
- );
- begin
- inherited create(
- ASourceTable,
- ATargetTable,
- ATransferAction
- );
- TransferCondition := ATransferCondition;
- end;
-
- { TTableActionScanner.Execute Procedure
- ----------------------------------------------------------------}
- procedure TTableActionScanner.Execute;
- begin
- SourceTable.DisableControls;
- SourceTable.First;
- while not SourceTable.Eof do
- begin
- Action( SourceTable ) ;
- SourceTable.Next;
- end;
- if SourceTable.State = dsEdit then
- SourceTable.Post;
- SourceTable.EnableControls;
- end;
-
- { TTableConditionalActionScanner.Execute Procedure
- ----------------------------------------------------------------}
- procedure TTableConditionalActionScanner.Execute;
- begin
- SourceTable.DisableControls;
- SourceTable.First;
- while not SourceTable.Eof do
- begin
- if Condition( SourceTable ) then
- Action( SourceTable ) ;
- SourceTable.Next;
- end;
- if SourceTable.State = dsEdit then
- SourceTable.Post;
- SourceTable.EnableControls;
- end;
-
- { TTableTransferScanner.Execute Procedure
- ----------------------------------------------------------------}
- procedure TTableTransferScanner.Execute;
- begin
- SourceTable.DisableControls;
- TargetTable.DisableControls;
- SourceTable.First;
- while not SourceTable.Eof do
- begin
- TransferAction( SourceTable, TargetTable ) ;
- SourceTable.Next;
- end;
- if TargetTable.State in [dsEdit, dsInsert] then
- TargetTable.Post;
- if SourceTable.State = dsEdit then
- SourceTable.Post;
- TargetTable.EnableControls;
- SourceTable.EnableControls;
- end;
-
- { TTableConditionalTransferScanner.Execute Procedure
- ----------------------------------------------------------------}
- procedure TTableConditionalTransferScanner.Execute;
- begin
- SourceTable.DisableControls;
- TargetTable.DisableControls;
- SourceTable.First;
- while not SourceTable.Eof do
- begin
- if TransferCondition( SourceTable ) then
- TransferAction( SourceTable, TargetTable ) ;
- SourceTable.Next;
- end;
- if TargetTable.State in [dsEdit, dsInsert] then
- TargetTable.Post;
- if SourceTable.State = dsEdit then
- SourceTable.Post;
- TargetTable.EnableControls;
- SourceTable.EnableControls;
- end;
-
- end.
-